home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / g_quake / dmmde321.zip / WEAPONS.QC < prev    next >
Text File  |  1996-08-16  |  26KB  |  1,237 lines

  1. /*
  2. */
  3. void (entity targ, entity inflictor, entity attacker, float damage) T_Damage;
  4. void () player_run;
  5. void(entity bomb, entity attacker, float rad, entity ignore) T_RadiusDamage;
  6. void(vector org, vector vel, float damage) SpawnBlood;
  7. void() SuperDamageSound;
  8.  
  9.  
  10. // called by worldspawn
  11. void() W_Precache =
  12. {
  13.     precache_sound ("weapons/r_exp3.wav");    // new rocket explosion
  14.     precache_sound ("weapons/rocket1i.wav");    // spike gun
  15.     precache_sound ("weapons/sgun1.wav");
  16.     precache_sound ("weapons/guncock.wav");    // player shotgun
  17.     precache_sound ("weapons/ric1.wav");    // ricochet (used in c code)
  18.     precache_sound ("weapons/ric2.wav");    // ricochet (used in c code)
  19.     precache_sound ("weapons/ric3.wav");    // ricochet (used in c code)
  20.     precache_sound ("weapons/spike2.wav");    // super spikes
  21.     precache_sound ("weapons/tink1.wav");    // spikes tink (used in c code)
  22.     precache_sound ("weapons/grenade.wav");    // grenade launcher
  23.     precache_sound ("weapons/bounce.wav");        // grenade bounce
  24.     precache_sound ("weapons/shotgn2.wav");    // super shotgun
  25. };
  26.  
  27. float() crandom =
  28. {
  29.     return 2*(random() - 0.5);
  30. };
  31.  
  32. /*
  33. ================
  34. W_FireAxe
  35. ================
  36. */
  37. void() W_FireAxe =
  38. {
  39.     local    vector    source;
  40.     local    vector    org;
  41.  
  42.     source = self.origin + '0 0 16';
  43.     traceline (source, source + v_forward*64, FALSE, self);
  44.     if (trace_fraction == 1.0)
  45.         return;
  46.     
  47.     org = trace_endpos - v_forward*4;
  48.  
  49.     if (trace_ent.takedamage)
  50.     {
  51.         trace_ent.axhitme = 1;
  52.         SpawnBlood (org, '0 0 0', 20);
  53.         T_Damage (trace_ent, self, self, 20);
  54.     }
  55.     else
  56.     {    // hit wall
  57.         sound (self, CHAN_WEAPON, "player/axhit2.wav", 1, ATTN_NORM);
  58.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  59.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  60.         WriteCoord (MSG_BROADCAST, org_x);
  61.         WriteCoord (MSG_BROADCAST, org_y);
  62.         WriteCoord (MSG_BROADCAST, org_z);
  63.     }
  64. };
  65.  
  66.  
  67. //============================================================================
  68.  
  69.  
  70. vector() wall_velocity =
  71. {
  72.     local vector    vel;
  73.     
  74.     vel = normalize (self.velocity);
  75.     vel = normalize(vel + v_up*(random()- 0.5) + v_right*(random()- 0.5));
  76.     vel = vel + 2*trace_plane_normal;
  77.     vel = vel * 200;
  78.     
  79.     return vel;
  80. };
  81.  
  82.  
  83. /*
  84. ================
  85. SpawnMeatSpray
  86. ================
  87. */
  88. void(vector org, vector vel) SpawnMeatSpray =
  89. {
  90.     local    entity missile, mpuff;
  91.     local    vector    org;
  92.  
  93.     missile = spawn ();
  94.     missile.owner = self;
  95.     missile.movetype = MOVETYPE_BOUNCE;
  96.     missile.solid = SOLID_NOT;
  97.  
  98.     makevectors (self.angles);
  99.  
  100.     missile.velocity = vel;
  101.     missile.velocity_z = missile.velocity_z + 250 + 50*random();
  102.  
  103.     missile.avelocity = '3000 1000 2000';
  104.     
  105. // set missile duration
  106.     missile.nextthink = time + 1;
  107.     missile.think = SUB_Remove;
  108.  
  109.     setmodel (missile, "progs/zom_gib.mdl");
  110.     setsize (missile, '0 0 0', '0 0 0');        
  111.     setorigin (missile, org);
  112. };
  113.  
  114. /*
  115. ================
  116. SpawnBlood
  117. ================
  118. */
  119. void(vector org, vector vel, float damage) SpawnBlood =
  120. {
  121.     particle (org, vel*0.1, 73, damage*2);
  122. };
  123.  
  124. /*
  125. ================
  126. spawn_touchblood
  127. ================
  128. */
  129. void(float damage) spawn_touchblood =
  130. {
  131.     local vector    vel;
  132.  
  133.     vel = wall_velocity () * 0.2;
  134.     SpawnBlood (self.origin + vel*0.01, vel, damage);
  135. };
  136.  
  137.  
  138. /*
  139. ================
  140. SpawnChunk
  141. ================
  142. */
  143. void(vector org, vector vel) SpawnChunk =
  144. {
  145.     particle (org, vel*0.02, 0, 10);
  146. };
  147.  
  148. /*
  149. ==============================================================================
  150.  
  151. MULTI-DAMAGE
  152.  
  153. Collects multiple small damages into a single damage
  154.  
  155. ==============================================================================
  156. */
  157.  
  158. entity    multi_ent;
  159. float    multi_damage;
  160.  
  161. void() ClearMultiDamage =
  162. {
  163.     multi_ent = world;
  164.     multi_damage = 0;
  165. };
  166.  
  167. void() ApplyMultiDamage =
  168. {
  169.     if (!multi_ent)
  170.         return;
  171.     T_Damage (multi_ent, self, self, multi_damage);
  172. };
  173.  
  174. void(entity hit, float damage) AddMultiDamage =
  175. {
  176.     if (!hit)
  177.         return;
  178.     
  179.     if (hit != multi_ent)
  180.     {
  181.         ApplyMultiDamage ();
  182.         multi_damage = damage;
  183.         multi_ent = hit;
  184.     }
  185.     else
  186.         multi_damage = multi_damage + damage;
  187. };
  188.  
  189. /*
  190. ==============================================================================
  191.  
  192. BULLETS
  193.  
  194. ==============================================================================
  195. */
  196.  
  197. /*
  198. ================
  199. TraceAttack
  200. ================
  201. */
  202. void(float damage, vector dir) TraceAttack =
  203. {
  204.     local    vector    vel, org;
  205.     
  206.     vel = normalize(dir + v_up*crandom() + v_right*crandom());
  207.     vel = vel + 2*trace_plane_normal;
  208.     vel = vel * 200;
  209.  
  210.     org = trace_endpos - dir*4;
  211.  
  212.     if (trace_ent.takedamage)
  213.     {
  214.         SpawnBlood (org, vel*0.2, damage);
  215.         AddMultiDamage (trace_ent, damage);
  216.     }
  217.     else
  218.     {
  219.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  220.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  221.         WriteCoord (MSG_BROADCAST, org_x);
  222.         WriteCoord (MSG_BROADCAST, org_y);
  223.         WriteCoord (MSG_BROADCAST, org_z);
  224.     }
  225. };
  226.  
  227. /*
  228. ================
  229. FireBullets
  230.  
  231. Used by shotgun, super shotgun, and enemy soldier firing
  232. Go to the trouble of combining multiple pellets into a single damage call.
  233. ================
  234. */
  235. void(float shotcount, vector dir, vector spread) FireBullets =
  236. {
  237.     local    vector direction;
  238.     local    vector    src;
  239.     
  240.     makevectors(self.v_angle);
  241.  
  242.     src = self.origin + v_forward*10;
  243.     src_z = self.absmin_z + self.size_z * 0.7;
  244.  
  245.     ClearMultiDamage ();
  246.     while (shotcount > 0)
  247.     {
  248.         direction = dir + crandom()*spread_x*v_right + crandom()*spread_y*v_up;
  249.  
  250.         traceline (src, src + direction*2048, FALSE, self);
  251.         if (trace_fraction != 1.0)
  252.             TraceAttack (4, direction);
  253.  
  254.         shotcount = shotcount - 1;
  255.     }
  256.     ApplyMultiDamage ();
  257. };
  258.  
  259. /*
  260. ================
  261. W_FireShotgun
  262. ================
  263. */
  264. void() W_FireShotgun =
  265. {
  266.     local vector dir;
  267.  
  268.     sound (self, CHAN_WEAPON, "weapons/guncock.wav", 1, ATTN_NORM);    
  269.  
  270.     self.punchangle_x = -2;
  271.     
  272.         if (deathmatch != 7)
  273.                 self.currentammo = self.ammo_shells = self.ammo_shells - 1;
  274.  
  275.     dir = aim (self, 100000);
  276.     FireBullets (6, dir, '0.04 0.04 0');
  277. };
  278.  
  279.  
  280. /*
  281. ================
  282. W_FireSuperShotgun
  283. ================
  284. */
  285. void() W_FireSuperShotgun =
  286. {
  287.     local vector dir;
  288.  
  289.     if (self.currentammo == 1)
  290.     {
  291.         W_FireShotgun ();
  292.         return;
  293.     }
  294.         
  295.     sound (self ,CHAN_WEAPON, "weapons/shotgn2.wav", 1, ATTN_NORM);    
  296.  
  297.     self.punchangle_x = -4;
  298.     
  299.         if (deathmatch != 7)
  300.                 self.currentammo = self.ammo_shells = self.ammo_shells - 2;
  301.     dir = aim (self, 100000);
  302.     FireBullets (14, dir, '0.14 0.08 0');
  303. };
  304.  
  305.  
  306. /*
  307. ==============================================================================
  308.  
  309. ROCKETS
  310.  
  311. ==============================================================================
  312. */
  313.  
  314. void()    s_explode1    =    [0,        s_explode2] {};
  315. void()    s_explode2    =    [1,        s_explode3] {};
  316. void()    s_explode3    =    [2,        s_explode4] {};
  317. void()    s_explode4    =    [3,        s_explode5] {};
  318. void()    s_explode5    =    [4,        s_explode6] {};
  319. void()    s_explode6    =    [5,        SUB_Remove] {};
  320.  
  321. void() BecomeExplosion =
  322. {
  323.     self.movetype = MOVETYPE_NONE;
  324.     self.velocity = '0 0 0';
  325.     self.touch = SUB_Null;
  326.     setmodel (self, "progs/s_explod.spr");
  327.     self.solid = SOLID_NOT;
  328.     s_explode1 ();
  329. };
  330.  
  331. void() T_MissileTouch =
  332. {
  333.     local float    damg;
  334.  
  335.     if (other == self.owner)
  336.         return;        // don't explode on owner
  337.  
  338.     if (pointcontents(self.origin) == CONTENT_SKY)
  339.     {
  340.         remove(self);
  341.         return;
  342.     }
  343.  
  344.     damg = 100 + random()*20;
  345.     
  346.     if (other.health)
  347.     {
  348.         if (other.classname == "monster_shambler")
  349.             damg = damg * 0.5;    // mostly immune
  350.         T_Damage (other, self, self.owner, damg );
  351.     }
  352.  
  353.     // don't do radius damage to the other, because all the damage
  354.     // was done in the impact
  355.     T_RadiusDamage (self, self.owner, 120, other);
  356.  
  357. //    sound (self, CHAN_WEAPON, "weapons/r_exp3.wav", 1, ATTN_NORM);
  358.     self.origin = self.origin - 8*normalize(self.velocity);
  359.  
  360.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  361.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  362.     WriteCoord (MSG_BROADCAST, self.origin_x);
  363.     WriteCoord (MSG_BROADCAST, self.origin_y);
  364.     WriteCoord (MSG_BROADCAST, self.origin_z);
  365.  
  366.     BecomeExplosion ();
  367. };
  368.  
  369.  
  370.  
  371. /*
  372. ================
  373. W_FireRocket
  374. ================
  375. */
  376. void() W_FireRocket =
  377. {
  378.     local    entity missile, mpuff;
  379.     
  380.         if (deathmatch != 7)
  381.                 self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  382.     
  383.     sound (self, CHAN_WEAPON, "weapons/sgun1.wav", 1, ATTN_NORM);
  384.  
  385.     self.punchangle_x = -2;
  386.  
  387.     missile = spawn ();
  388.     missile.owner = self;
  389.     missile.movetype = MOVETYPE_FLYMISSILE;
  390.     missile.solid = SOLID_BBOX;
  391.         
  392. // set missile speed    
  393.  
  394.     makevectors (self.v_angle);
  395.     missile.velocity = aim(self, 1000);
  396.     missile.velocity = missile.velocity * 1000;
  397.     missile.angles = vectoangles(missile.velocity);
  398.     
  399.     missile.touch = T_MissileTouch;
  400.     
  401. // set missile duration
  402.     missile.nextthink = time + 5;
  403.     missile.think = SUB_Remove;
  404.  
  405.     setmodel (missile, "progs/missile.mdl");
  406.     setsize (missile, '0 0 0', '0 0 0');        
  407.     setorigin (missile, self.origin + v_forward*8 + '0 0 16');
  408. };
  409.  
  410. /*
  411. ===============================================================================
  412.  
  413. LIGHTNING
  414.  
  415. ===============================================================================
  416. */
  417.  
  418. /*
  419. =================
  420. LightningDamage
  421. =================
  422. */
  423. void(vector p1, vector p2, entity from, float damage) LightningDamage =
  424. {
  425.     local entity        e1, e2;
  426.     local vector        f;
  427.     
  428.     f = p2 - p1;
  429.     normalize (f);
  430.     f_x = 0 - f_y;
  431.     f_y = f_x;
  432.     f_z = 0;
  433.     f = f*16;
  434.  
  435.     e1 = e2 = world;
  436.  
  437.     traceline (p1, p2, FALSE, self);
  438.     if (trace_ent.takedamage)
  439.     {
  440.         particle (trace_endpos, '0 0 100', 225, damage*4);
  441.         T_Damage (trace_ent, from, from, damage);
  442.         if (self.classname == "player")
  443.         {
  444.             if (other.classname == "player")
  445.                 trace_ent.velocity_z = trace_ent.velocity_z + 400;
  446.         }
  447.     }
  448.     e1 = trace_ent;
  449.  
  450.     traceline (p1 + f, p2 + f, FALSE, self);
  451.     if (trace_ent != e1 && trace_ent.takedamage)
  452.     {
  453.         particle (trace_endpos, '0 0 100', 225, damage*4);
  454.         T_Damage (trace_ent, from, from, damage);
  455.     }
  456.     e2 = trace_ent;
  457.  
  458.     traceline (p1 - f, p2 - f, FALSE, self);
  459.     if (trace_ent != e1 && trace_ent != e2 && trace_ent.takedamage)
  460.     {
  461.         particle (trace_endpos, '0 0 100', 225, damage*4);
  462.         T_Damage (trace_ent, from, from, damage);
  463.     }
  464. };
  465.  
  466.  
  467. void() W_FireLightning =
  468. {
  469.     local    vector        org;
  470.  
  471.     if (self.ammo_cells < 1)
  472.     {
  473.         self.weapon = W_BestWeapon ();
  474.         W_SetCurrentAmmo ();
  475.         return;
  476.     }
  477.  
  478. // explode if under water
  479.     if (self.waterlevel > 1)
  480.     {
  481.         T_RadiusDamage (self, self, 35*self.ammo_cells, world);
  482.         self.ammo_cells = 0;
  483.         W_SetCurrentAmmo ();
  484.         return;
  485.     }
  486.  
  487.     if (self.t_width < time)
  488.     {
  489.         sound (self, CHAN_WEAPON, "weapons/lhit.wav", 1, ATTN_NORM);
  490.         self.t_width = time + 0.6;
  491.     }
  492.     self.punchangle_x = -2;
  493.  
  494.         if (deathmatch != 7)
  495.                 self.currentammo = self.ammo_cells = self.ammo_cells - 1;
  496.  
  497.     org = self.origin + '0 0 16';
  498.     
  499.     traceline (org, org + v_forward*600, TRUE, self);
  500.  
  501.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  502.     WriteByte (MSG_BROADCAST, TE_LIGHTNING2);
  503.     WriteEntity (MSG_BROADCAST, self);
  504.     WriteCoord (MSG_BROADCAST, org_x);
  505.     WriteCoord (MSG_BROADCAST, org_y);
  506.     WriteCoord (MSG_BROADCAST, org_z);
  507.     WriteCoord (MSG_BROADCAST, trace_endpos_x);
  508.     WriteCoord (MSG_BROADCAST, trace_endpos_y);
  509.     WriteCoord (MSG_BROADCAST, trace_endpos_z);
  510.  
  511.     LightningDamage (self.origin, trace_endpos + v_forward*4, self, 30);
  512. };
  513.  
  514.  
  515. //=============================================================================
  516.  
  517.  
  518. void() GrenadeExplode =
  519. {
  520.     T_RadiusDamage (self, self.owner, 120, world);
  521.  
  522.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  523.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  524.     WriteCoord (MSG_BROADCAST, self.origin_x);
  525.     WriteCoord (MSG_BROADCAST, self.origin_y);
  526.     WriteCoord (MSG_BROADCAST, self.origin_z);
  527.  
  528.     BecomeExplosion ();
  529. };
  530.  
  531. void() GrenadeTouch =
  532. {
  533.         if (other == self.owner)
  534.                 return;         // don't explode on owner   
  535.     if (other.takedamage == DAMAGE_AIM)
  536.     {
  537.         GrenadeExplode();
  538.         return;
  539.     }
  540.     sound (self, CHAN_WEAPON, "weapons/bounce.wav", 1, ATTN_NORM);    // bounce sound
  541.     if (self.velocity == '0 0 0')
  542.         self.avelocity = '0 0 0';
  543. };
  544.  
  545. /*
  546. ================
  547. W_FireGrenade
  548. ================
  549. */
  550. void() W_FireGrenade =
  551. {
  552.     local    entity missile, mpuff;
  553.     
  554.         if (deathmatch != 7)
  555.                 self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  556.     
  557.     sound (self, CHAN_WEAPON, "weapons/grenade.wav", 1, ATTN_NORM);
  558.  
  559.     self.punchangle_x = -2;
  560.  
  561.     missile = spawn ();
  562.     missile.owner = self;
  563.     missile.movetype = MOVETYPE_BOUNCE;
  564.     missile.solid = SOLID_BBOX;
  565.     missile.classname = "grenade";
  566.         
  567. // set missile speed    
  568.  
  569.     makevectors (self.v_angle);
  570.  
  571.     if (self.v_angle_x)
  572.         missile.velocity = v_forward*600 + v_up * 200 + crandom()*v_right*10 + crandom()*v_up*10;
  573.     else
  574.     {
  575.         missile.velocity = aim(self, 10000);
  576.         missile.velocity = missile.velocity * 600;
  577.         missile.velocity_z = 200;
  578.     }
  579.  
  580.     missile.avelocity = '300 300 300';
  581.  
  582.     missile.angles = vectoangles(missile.velocity);
  583.     
  584.     missile.touch = GrenadeTouch;
  585.     
  586. // set missile duration
  587.         missile.nextthink = time + 3;
  588.     missile.think = GrenadeExplode;
  589.  
  590.     setmodel (missile, "progs/grenade.mdl");
  591.     setsize (missile, '0 0 0', '0 0 0');        
  592.     setorigin (missile, self.origin);
  593. };
  594.  
  595.  
  596. //=============================================================================
  597.  
  598. void() spike_touch;
  599. void() superspike_touch;
  600.  
  601.  
  602. /*
  603. ===============
  604. launch_spike
  605.  
  606. Used for both the player and the ogre
  607. ===============
  608. */
  609. void(vector org, vector dir) launch_spike =
  610. {
  611.     newmis = spawn ();
  612.     newmis.owner = self;
  613.     newmis.movetype = MOVETYPE_FLYMISSILE;
  614.     newmis.solid = SOLID_BBOX;
  615.  
  616.     newmis.angles = vectoangles(dir);
  617.     
  618.     newmis.touch = spike_touch;
  619.     newmis.classname = "spike";
  620.     newmis.think = SUB_Remove;
  621.     newmis.nextthink = time + 6;
  622.     setmodel (newmis, "progs/spike.mdl");
  623.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);        
  624.     setorigin (newmis, org);
  625.  
  626.     newmis.velocity = dir * 1000;
  627. };
  628.  
  629. void() W_FireSuperSpikes =
  630. {
  631.     local vector    dir;
  632.     local entity    old;
  633.     
  634.     sound (self, CHAN_WEAPON, "weapons/spike2.wav", 1, ATTN_NORM);
  635.     self.attack_finished = time + 0.2;
  636.         if (deathmatch != 7)
  637.                 self.currentammo = self.ammo_nails = self.ammo_nails - 2;
  638.     dir = aim (self, 1000);
  639.     launch_spike (self.origin + '0 0 16', dir);
  640.     newmis.touch = superspike_touch;
  641.     setmodel (newmis, "progs/s_spike.mdl");
  642.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);        
  643.     self.punchangle_x = -2;
  644. };
  645.  
  646. void(float ox) W_FireSpikes =
  647. {
  648.     local vector    dir;
  649.     local entity    old;
  650.     
  651.     makevectors (self.v_angle);
  652.     
  653.     if (self.ammo_nails >= 2 && self.weapon == IT_SUPER_NAILGUN)
  654.     {
  655.         W_FireSuperSpikes ();
  656.         return;
  657.     }
  658.  
  659.     if (self.ammo_nails < 1)
  660.     {
  661.         self.weapon = W_BestWeapon ();
  662.         W_SetCurrentAmmo ();
  663.         return;
  664.     }
  665.  
  666.     sound (self, CHAN_WEAPON, "weapons/rocket1i.wav", 1, ATTN_NORM);
  667.     self.attack_finished = time + 0.2;
  668.         if (deathmatch != 7)
  669.                 self.currentammo = self.ammo_nails = self.ammo_nails - 1;
  670.     dir = aim (self, 1000);
  671.     launch_spike (self.origin + '0 0 16' + v_right*ox, dir);
  672.  
  673.     self.punchangle_x = -2;
  674. };
  675.  
  676.  
  677.  
  678. .float hit_z;
  679. void() spike_touch =
  680. {
  681. local float rand;
  682.     if (other == self.owner)
  683.         return;
  684.  
  685.     if (other.solid == SOLID_TRIGGER)
  686.         return;    // trigger field, do nothing
  687.  
  688.     if (pointcontents(self.origin) == CONTENT_SKY)
  689.     {
  690.         remove(self);
  691.         return;
  692.     }
  693.     
  694. // hit something that bleeds
  695.     if (other.takedamage)
  696.     {
  697.         spawn_touchblood (9);
  698.         T_Damage (other, self, self.owner, 9);
  699.     }
  700.     else
  701.     {
  702.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  703.         
  704.         if (self.classname == "wizspike")
  705.             WriteByte (MSG_BROADCAST, TE_WIZSPIKE);
  706.         else if (self.classname == "knightspike")
  707.             WriteByte (MSG_BROADCAST, TE_KNIGHTSPIKE);
  708.         else
  709.             WriteByte (MSG_BROADCAST, TE_SPIKE);
  710.         WriteCoord (MSG_BROADCAST, self.origin_x);
  711.         WriteCoord (MSG_BROADCAST, self.origin_y);
  712.         WriteCoord (MSG_BROADCAST, self.origin_z);
  713.     }
  714.  
  715.     remove(self);
  716.  
  717. };
  718.  
  719. void() superspike_touch =
  720. {
  721. local float rand;
  722.     if (other == self.owner)
  723.         return;
  724.  
  725.     if (other.solid == SOLID_TRIGGER)
  726.         return;    // trigger field, do nothing
  727.  
  728.     if (pointcontents(self.origin) == CONTENT_SKY)
  729.     {
  730.         remove(self);
  731.         return;
  732.     }
  733.     
  734. // hit something that bleeds
  735.     if (other.takedamage)
  736.     {
  737.         spawn_touchblood (18);
  738.         T_Damage (other, self, self.owner, 18);
  739.     }
  740.     else
  741.     {
  742.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  743.         WriteByte (MSG_BROADCAST, TE_SUPERSPIKE);
  744.         WriteCoord (MSG_BROADCAST, self.origin_x);
  745.         WriteCoord (MSG_BROADCAST, self.origin_y);
  746.         WriteCoord (MSG_BROADCAST, self.origin_z);
  747.     }
  748.  
  749.     remove(self);
  750.  
  751. };
  752.  
  753.  
  754. /*
  755. ===============================================================================
  756.  
  757. PLAYER WEAPON USE
  758.  
  759. ===============================================================================
  760. */
  761.  
  762. void() W_SetCurrentAmmo =
  763. {
  764.     player_run ();        // get out of any weapon firing states
  765.  
  766.     self.items = self.items - ( self.items & (IT_SHELLS | IT_NAILS | IT_ROCKETS | IT_CELLS) );
  767.     
  768.     if (self.weapon == IT_AXE)
  769.     {
  770.         self.currentammo = 0;
  771.         self.weaponmodel = "progs/v_axe.mdl";
  772.         self.weaponframe = 0;
  773.     }
  774.     else if (self.weapon == IT_SHOTGUN)
  775.     {
  776.         self.currentammo = self.ammo_shells;
  777.         self.weaponmodel = "progs/v_shot.mdl";
  778.         self.weaponframe = 0;
  779.         self.items = self.items | IT_SHELLS;
  780.     }
  781.     else if (self.weapon == IT_SUPER_SHOTGUN)
  782.     {
  783.         self.currentammo = self.ammo_shells;
  784.         self.weaponmodel = "progs/v_shot2.mdl";
  785.         self.weaponframe = 0;
  786.         self.items = self.items | IT_SHELLS;
  787.     }
  788.     else if (self.weapon == IT_NAILGUN)
  789.     {
  790.         self.currentammo = self.ammo_nails;
  791.         self.weaponmodel = "progs/v_nail.mdl";
  792.         self.weaponframe = 0;
  793.         self.items = self.items | IT_NAILS;
  794.     }
  795.     else if (self.weapon == IT_SUPER_NAILGUN)
  796.     {
  797.         self.currentammo = self.ammo_nails;
  798.         self.weaponmodel = "progs/v_nail2.mdl";
  799.         self.weaponframe = 0;
  800.         self.items = self.items | IT_NAILS;
  801.     }
  802.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  803.     {
  804.         self.currentammo = self.ammo_rockets;
  805.         self.weaponmodel = "progs/v_rock.mdl";
  806.         self.weaponframe = 0;
  807.         self.items = self.items | IT_ROCKETS;
  808.     }
  809.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  810.     {
  811.         self.currentammo = self.ammo_rockets;
  812.         self.weaponmodel = "progs/v_rock2.mdl";
  813.         self.weaponframe = 0;
  814.         self.items = self.items | IT_ROCKETS;
  815.     }
  816.     else if (self.weapon == IT_LIGHTNING)
  817.     {
  818.         self.currentammo = self.ammo_cells;
  819.         self.weaponmodel = "progs/v_light.mdl";
  820.         self.weaponframe = 0;
  821.         self.items = self.items | IT_CELLS;
  822.     }
  823.     else
  824.     {
  825.         self.currentammo = 0;
  826.         self.weaponmodel = "";
  827.         self.weaponframe = 0;
  828.     }
  829. };
  830.  
  831. float() W_BestWeapon =
  832. {
  833.     local    float    it;
  834.     
  835.     it = self.items;
  836.  
  837.     if(self.ammo_cells >= 1 && (it & IT_LIGHTNING) )
  838.         return IT_LIGHTNING;
  839.     else if(self.ammo_nails >= 2 && (it & IT_SUPER_NAILGUN) )
  840.         return IT_SUPER_NAILGUN;
  841.     else if(self.ammo_shells >= 2 && (it & IT_SUPER_SHOTGUN) )
  842.         return IT_SUPER_SHOTGUN;
  843.     else if(self.ammo_nails >= 1 && (it & IT_NAILGUN) )
  844.         return IT_NAILGUN;
  845.     else if(self.ammo_shells >= 1 && (it & IT_SHOTGUN) )
  846.         return IT_SHOTGUN;
  847.         
  848. /*
  849.     if(self.ammo_rockets >= 1 && (it & IT_ROCKET_LAUNCHER) )
  850.         return IT_ROCKET_LAUNCHER;
  851.     else if(self.ammo_rockets >= 1 && (it & IT_GRENADE_LAUNCHER) )
  852.         return IT_GRENADE_LAUNCHER;
  853.  
  854. */
  855.  
  856.     return IT_AXE;
  857. };
  858.  
  859. float() W_CheckNoAmmo =
  860. {
  861.     if (self.currentammo > 0)
  862.         return TRUE;
  863.  
  864.     if (self.weapon == IT_AXE)
  865.         return TRUE;
  866.     
  867.     self.weapon = W_BestWeapon ();
  868.  
  869.     W_SetCurrentAmmo ();
  870.     
  871. // drop the weapon down
  872.     return FALSE;
  873. };
  874.  
  875. /*
  876. ============
  877. W_Attack
  878.  
  879. An attack impulse can be triggered now
  880. ============
  881. */
  882. void()    player_axe1;
  883. void()    player_axeb1;
  884. void()    player_axec1;
  885. void()    player_axed1;
  886. void()    player_shot1;
  887. void()    player_nail1;
  888. void()    player_light1;
  889. void()    player_rocket1;
  890.  
  891. void() W_Attack =
  892. {
  893.     local    float    r;
  894.  
  895.     if (!W_CheckNoAmmo ())
  896.         return;
  897.  
  898.     makevectors    (self.v_angle);            // calculate forward angle for velocity
  899.     self.show_hostile = time + 1;    // wake monsters up
  900.  
  901.     if (self.weapon == IT_AXE)
  902.     {
  903.         sound (self, CHAN_WEAPON, "weapons/ax1.wav", 1, ATTN_NORM);
  904.         r = random();
  905.         if (r < 0.25)
  906.             player_axe1 ();
  907.         else if (r<0.5)
  908.             player_axeb1 ();
  909.         else if (r<0.75)
  910.             player_axec1 ();
  911.         else
  912.             player_axed1 ();
  913.         self.attack_finished = time + 0.5;
  914.     }
  915.     else if (self.weapon == IT_SHOTGUN)
  916.     {
  917.         player_shot1 ();
  918.         W_FireShotgun ();
  919.                 self.attack_finished = time + 0.5;
  920.     }
  921.     else if (self.weapon == IT_SUPER_SHOTGUN)
  922.     {
  923.         player_shot1 ();
  924.         W_FireSuperShotgun ();
  925.                 self.attack_finished = time + 0.7;
  926.     }
  927.     else if (self.weapon == IT_NAILGUN)
  928.     {
  929.         player_nail1 ();
  930.     }
  931.     else if (self.weapon == IT_SUPER_NAILGUN)
  932.     {
  933.         player_nail1 ();
  934.     }
  935.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  936.     {
  937.         player_rocket1();
  938.                 W_FireGrenade();
  939.                 self.attack_finished = time + 0.6;
  940.         }
  941.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  942.     {
  943.         player_rocket1();
  944.         W_FireRocket();
  945.                 self.attack_finished = time + 0.8;
  946.     }
  947.     else if (self.weapon == IT_LIGHTNING)
  948.     {
  949.         player_light1();
  950.         self.attack_finished = time + 0.1;
  951.         sound (self, CHAN_AUTO, "weapons/lstart.wav", 1, ATTN_NORM);
  952.     }
  953. };
  954.  
  955. /*
  956. ============
  957. W_ChangeWeapon
  958.  
  959. ============
  960. */
  961. void() W_ChangeWeapon =
  962. {
  963.     local    float    it, am, fl;
  964.     
  965.     it = self.items;
  966.     am = 0;
  967.     
  968.     if (self.impulse == 1)
  969.     {
  970.         fl = IT_AXE;
  971.     }
  972.     else if (self.impulse == 2)
  973.     {
  974.         fl = IT_SHOTGUN;
  975.         if (self.ammo_shells < 1)
  976.             am = 1;
  977.     }
  978.     else if (self.impulse == 3)
  979.     {
  980.         fl = IT_SUPER_SHOTGUN;
  981.         if (self.ammo_shells < 2)
  982.             am = 1;
  983.     }        
  984.     else if (self.impulse == 4)
  985.     {
  986.         fl = IT_NAILGUN;
  987.         if (self.ammo_nails < 1)
  988.             am = 1;
  989.     }
  990.     else if (self.impulse == 5)
  991.     {
  992.         fl = IT_SUPER_NAILGUN;
  993.         if (self.ammo_nails < 2)
  994.             am = 1;
  995.     }
  996.     else if (self.impulse == 6)
  997.     {
  998.         fl = IT_GRENADE_LAUNCHER;
  999.         if (self.ammo_rockets < 1)
  1000.             am = 1;
  1001.     }
  1002.     else if (self.impulse == 7)
  1003.     {
  1004.         fl = IT_ROCKET_LAUNCHER;
  1005.         if (self.ammo_rockets < 1)
  1006.             am = 1;
  1007.     }
  1008.     else if (self.impulse == 8)
  1009.     {
  1010.         fl = IT_LIGHTNING;
  1011.         if (self.ammo_cells < 1)
  1012.             am = 1;
  1013.     }
  1014.  
  1015.     self.impulse = 0;
  1016.     
  1017.     if (!(self.items & fl))
  1018.     {    // don't have the weapon or the ammo
  1019.         sprint (self, "no weapon.\n");
  1020.         return;
  1021.     }
  1022.     
  1023.     if (am)
  1024.     {    // don't have the ammo
  1025.         sprint (self, "not enough ammo.\n");
  1026.         return;
  1027.     }
  1028.  
  1029. //
  1030. // set weapon, set ammo
  1031. //
  1032.     self.weapon = fl;        
  1033.     W_SetCurrentAmmo ();
  1034. };
  1035.  
  1036. /*
  1037. ============
  1038. CheatCommand
  1039. ============
  1040. */
  1041. void() CheatCommand =
  1042. {
  1043.         if (deathmatch || coop)
  1044.                 return;
  1045.  
  1046.     self.ammo_rockets = 100;
  1047.     self.ammo_nails = 200;
  1048.     self.ammo_shells = 100;
  1049.     self.items = self.items | 
  1050.         IT_AXE |
  1051.         IT_SHOTGUN |
  1052.         IT_SUPER_SHOTGUN |
  1053.         IT_NAILGUN |
  1054.         IT_SUPER_NAILGUN |
  1055.         IT_GRENADE_LAUNCHER |
  1056.         IT_ROCKET_LAUNCHER |
  1057.         IT_KEY1 | IT_KEY2;
  1058.  
  1059.     self.ammo_cells = 200;
  1060.     self.items = self.items | IT_LIGHTNING;
  1061.  
  1062.     self.weapon = IT_ROCKET_LAUNCHER;
  1063.     self.impulse = 0;
  1064.     W_SetCurrentAmmo ();
  1065. };
  1066.  
  1067. /*
  1068. ============
  1069. CycleWeaponCommand
  1070.  
  1071. Go to the next weapon with ammo
  1072. ============
  1073. */
  1074. void() CycleWeaponCommand =
  1075. {
  1076.     local    float    it, am;
  1077.     
  1078.     it = self.items;
  1079.     self.impulse = 0;
  1080.     
  1081.     while (1)
  1082.     {
  1083.         am = 0;
  1084.  
  1085.         if (self.weapon == IT_LIGHTNING)
  1086.         {
  1087.             self.weapon = IT_AXE;
  1088.         }
  1089.         else if (self.weapon == IT_AXE)
  1090.         {
  1091.             self.weapon = IT_SHOTGUN;
  1092.             if (self.ammo_shells < 1)
  1093.                 am = 1;
  1094.         }
  1095.         else if (self.weapon == IT_SHOTGUN)
  1096.         {
  1097.             self.weapon = IT_SUPER_SHOTGUN;
  1098.             if (self.ammo_shells < 2)
  1099.                 am = 1;
  1100.         }        
  1101.         else if (self.weapon == IT_SUPER_SHOTGUN)
  1102.         {
  1103.             self.weapon = IT_NAILGUN;
  1104.             if (self.ammo_nails < 1)
  1105.                 am = 1;
  1106.         }
  1107.         else if (self.weapon == IT_NAILGUN)
  1108.         {
  1109.             self.weapon = IT_SUPER_NAILGUN;
  1110.             if (self.ammo_nails < 2)
  1111.                 am = 1;
  1112.         }
  1113.         else if (self.weapon == IT_SUPER_NAILGUN)
  1114.         {
  1115.             self.weapon = IT_GRENADE_LAUNCHER;
  1116.             if (self.ammo_rockets < 1)
  1117.                 am = 1;
  1118.         }
  1119.         else if (self.weapon == IT_GRENADE_LAUNCHER)
  1120.         {
  1121.             self.weapon = IT_ROCKET_LAUNCHER;
  1122.             if (self.ammo_rockets < 1)
  1123.                 am = 1;
  1124.         }
  1125.         else if (self.weapon == IT_ROCKET_LAUNCHER)
  1126.         {
  1127.             self.weapon = IT_LIGHTNING;
  1128.             if (self.ammo_cells < 1)
  1129.                 am = 1;
  1130.         }
  1131.     
  1132.         if ( (self.items & self.weapon) && am == 0)
  1133.         {
  1134.             W_SetCurrentAmmo ();
  1135.             return;
  1136.         }
  1137.     }
  1138.  
  1139. };
  1140.  
  1141. /*
  1142. ============
  1143. ServerflagsCommand
  1144.  
  1145. Just for development
  1146. ============
  1147. */
  1148. void() ServerflagsCommand =
  1149. {
  1150.     serverflags = serverflags * 2 + 1;
  1151. };
  1152.  
  1153. void() QuadCheat =
  1154. {
  1155.         if (deathmatch || coop)
  1156.                 return;
  1157.     self.super_time = 1;
  1158.     self.super_damage_finished = time + 30;
  1159.     self.items = self.items | IT_QUAD;
  1160.     dprint ("quad cheat\n");
  1161. };
  1162.  
  1163. /*
  1164. ============
  1165. ImpulseCommands
  1166.  
  1167. ============
  1168. */
  1169. void() ImpulseCommands =
  1170. {
  1171.     if (self.impulse >= 1 && self.impulse <= 8)
  1172.         W_ChangeWeapon ();
  1173.  
  1174.     if (self.impulse == 9)
  1175.         CheatCommand ();
  1176.     if (self.impulse == 10)
  1177.         CycleWeaponCommand ();
  1178.     if (self.impulse == 11)
  1179.         ServerflagsCommand ();
  1180.  
  1181.         if (self.impulse == 254)
  1182.         {
  1183.                 self.items = self.items | IT_INVULNERABILITY;
  1184.                 self.invincible_time = 1;
  1185.                 self.invincible_finished = time + 30;
  1186.         }
  1187.  
  1188.         if (self.impulse == 255)
  1189.         QuadCheat ();
  1190.         
  1191.     self.impulse = 0;
  1192. };
  1193.  
  1194. /*
  1195. ============
  1196. W_WeaponFrame
  1197.  
  1198. Called every frame so impulse events can be handled as well as possible
  1199. ============
  1200. */
  1201. void() W_WeaponFrame =
  1202. {
  1203.     if (time < self.attack_finished)
  1204.         return;
  1205.  
  1206.     ImpulseCommands ();
  1207.     
  1208. // check for attack
  1209.     if (self.button0)
  1210.     {
  1211.         SuperDamageSound ();
  1212.         W_Attack ();
  1213.     }
  1214. };
  1215.  
  1216. /*
  1217. ========
  1218. SuperDamageSound
  1219.  
  1220. Plays sound if needed
  1221. ========
  1222. */
  1223. void() SuperDamageSound =
  1224. {
  1225.     if (self.super_damage_finished > time)
  1226.     {
  1227.         if (self.super_sound < time)
  1228.         {
  1229.             self.super_sound = time + 1;
  1230.             sound (self, CHAN_BODY, "items/damage3.wav", 1, ATTN_NORM);
  1231.         }
  1232.     }
  1233.     return;
  1234. };
  1235.  
  1236.  
  1237.